package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 护理任务关联 Controller
 */
@RestController
@RequestMapping("nursing_project")
@Api(tags = "护理任务")
public class NursingProjectController extends BaseController{
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * @param name:
     * @param status:
     * @param pageNum:
     * @param pageSize:
     分页查询
     */
    @GetMapping
    @ApiOperation(value = "分页条件查询",notes = "传入分页参数")
    public ResponseResult queryPage(
            @ApiParam(value = "护理项目名称")
            @RequestParam(value = "name", required = false) String name,
            @ApiParam(value = "状态：0-禁用，1-启用")
            @RequestParam(value = "status", required = false) Integer status,
            @ApiParam(value = "当前页码")
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页显示数量")
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize){
        PageResponse<NursingProjectVo> page=nursingProjectService.queryPage(name,status,pageNum,pageSize);
        return success(page);
    }
    @PostMapping
    @ApiOperation(value = "添加",notes = "传入护理任务对象")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        int row=nursingProjectService.addNursingProject(nursingProjectDto);
        return toAjax(row);
    }


    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查询",notes = "id")
    public ResponseResult getNursingProjectById(@PathVariable Long id){
        NursingProjectVo nursingProject=nursingProjectService.getNpById(id);
        return success(nursingProject);
    }

    @PutMapping
    @ApiOperation(value = "根据ID修改",notes = "id")
    public ResponseResult updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto){
        int row=nursingProjectService.updateNursingProject(nursingProjectDto);
        return toAjax(row);
    }
    @DeleteMapping("{id}")
    @ApiOperation("根据ID删除")
    public ResponseResult deleteNursingProjectById(@PathVariable Long id){
        int row=nursingProjectService.deleteNursingProjectByID(id);
        return toAjax(row);
    }

    @PutMapping("/{id}/{status}")
    @ApiOperation("修改状态")
    public ResponseResult updateStauts(@PathVariable Long id,@PathVariable Integer status){
        int row=nursingProjectService.updateStauts(id,status);
        return toAjax(row);
    }
    @GetMapping("/all")
    @ApiOperation("查询所有护理项目")
    public ResponseResult getAll(){
       List<NursingProjectVo> all=nursingProjectService.getAll();
       return success(all);
    }
}
